﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TS.Bussiness;
using TS.Commons;
using TS.Entities;

namespace Tranco
{
    public partial class ScheduleDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["TracoUserId"] == null)
                {
                    ClientAlert("Đăng nhập để xem thông tin lịch trình.");
                    return;
                }
                HiddenFieldId.Value = Request.QueryString["sid"];

                LoadSchedule();
            }
        }
        private void LoadSchedule()
        {
            try
            {


                ScheduleBussiness bu = new ScheduleBussiness();
                Schedule obj = bu.GetScheduleById(HiddenFieldId.Value.ToNumeric());
               
                if (obj == null) return;

                if (Session["TracoGroupId"].ToStringOrDefault() == "5" && !string.Equals(obj.OwnerId.ToStringOrDefault(), Session["TracoOwnerId"].ToStringOrDefault()))
                {
                    ClientAlert("Không có quyền xem thông tin lịch trình này.");
                    return;
                }
                drOwner.Text = obj.OwnerName.ToStringOrDefault();
                drGateway.Text = obj.GateWayName.ToStringOrDefault();
                drNumberBike.Text = obj.NumberPlate.ToStringOrDefault();
                drStatus.Text = obj.Status.ToStringOrDefault();

                txtDetails.Text = obj.Content;
                txtStartDate.Text = obj.StartDateS;
                txtEndDate.Text = obj.EndDateS;
                txtNumberCont.Text = obj.NumberCont.ToStringOrDefault();
            }
            catch
            {

            }
        }

        public void ClientAlert(string strAlert)
        {
            var strScript = new StringBuilder();
            strScript.Append("<script language=JavaScript>");
            string scriptString = string.Format(CultureInfo.CurrentCulture, @"window.alert('" + strAlert + "');</script> ");
            strScript.Append(scriptString);
            ClientScript.RegisterStartupScript(GetType(), "Pop", strScript.ToString());
        }
    }
}